package com.cskaoyan.controller;


import com.cskaoyan.bean.Brand;
import com.cskaoyan.service.BrandService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.BrandVo;
import com.cskaoyan.vo.CreateBrandVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 接口功能：品牌
 * @author chen11
 */
@RestController
public class BrandController {

    @Autowired
    BrandService brandService;

    //查看品牌list
    @RequestMapping("admin/brand/list")
    public BaseRespVo getBrandList(Integer page, Integer limit, Integer id, String name, String sort, String order){

        BrandVo brands = brandService.selectBrandList(page,limit, id,name, sort, order);

        return BaseRespVo.ok(brands);
    }

    //删除品牌
    @RequestMapping("admin/brand/delete")
    //接受json中的id参数
    public BaseRespVo deleteBrand(@RequestBody  Brand brand){

        brandService.deleteBrand(brand.getId());

        return BaseRespVo.ok();
    }

    //更新品牌
    @RequestMapping("admin/brand/update")
    //接受json中的id参数
    public BaseRespVo updateBrand(@RequestBody  Brand brand){

        Brand brand1 = brandService.updateBrand(brand);

        return BaseRespVo.ok(brand1);
    }

    //todo:上传新的品牌商未完成
    @RequestMapping("admin/brand/create")
    //接受json中的id参数
    public BaseRespVo createBrand(@RequestBody  Brand brand){

        CreateBrandVo createBrandVo = brandService.createBrand(brand);

        return BaseRespVo.ok(createBrandVo);
    }



}
